<%@ page language="Java" import="java.util.*,descriptor.*,cv.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	SectorsListDescriptor sectPref = (SectorsListDescriptor)request.getAttribute("sectPref");
	CitiesListDescriptor citiesPref = (CitiesListDescriptor)request.getAttribute("citiesPref");
	CountriesListDescriptor countriesPref = (CountriesListDescriptor)request.getAttribute("countriesPref");
	SectorsListDescriptor sectors = (SectorsListDescriptor)request.getAttribute("sectors");
	CitiesListDescriptor cities = (CitiesListDescriptor)request.getAttribute("cities");
	CountriesListDescriptor countries = (CountriesListDescriptor)request.getAttribute("countries");
	String error1 = (String)request.getAttribute("error1");
	
	String title = "";
	String legend = "";
	String pref = "";
	String notif = "";
	if(sectors != null)
	{
		title = "Sector's Preference";
		legend = "Sector";
		pref = "1";
	}
	if(cities != null)
	{
		title = "City's Preference";
		legend = "City";
		pref = "2";
	}
	if(countries != null)
	{
		title = "Country's Preference";
		legend = "Country";
		pref = "3";
	}
	if(error1 != null)
	{
		notif ="<p style=\"color:red; font-size: 10px;\">" + error1 + "</p>";
	}
%>

<html>
	<jsp:include page="StudentHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Student" />
	</jsp:include>
	<body OnLoad="showmenu(document.getElementById('smenu4'));">
		<jsp:include page="StudentPageHeader.jsp"></jsp:include>
		<div id="container">
			<jsp:include page="StudentMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Student - <%= title %></h3>
				<div class="entry">
					<%= notif %>
					<form name="setPref" method="post">
						<input type="hidden" name="action" value="prefSet">
						<input type="hidden" name="pref" value="<%= pref %>"> 
						<fieldset>
							<legend>Set your preferences for <%= legend %></legend>
							<%
								if(sectors != null)
								{
									
									int size = sectors.sizeSectorList();
									for(int i=0 ; i<size ; i++)
									{
										String checked = "";
										if(sectPref != null)
										{
											int size2 = sectPref.sizeSectorList();
											for(int j= 0 ; j<size2 ; j++)
											{
												if(sectors.getSectorDescriptors().elementAt(i).getID() == sectPref.getSectorDescriptors().elementAt(j).getID())
												{
													checked = "checked";
												}
											}
										}
							%>
								<input type="checkbox" name="chbx" value="<%= sectors.getSectorDescriptors().elementAt(i).getID() %>" <%= checked %>> <%= sectors.getSectorDescriptors().elementAt(i).getName() %>
							<% 			
									}
								}
								if(cities != null)
								{
									int size = cities.sizeCitiesList();
									for(int i=0 ; i<size ; i++)
									{
										String checked = "";
										if(citiesPref != null)
										{
											int size2 = citiesPref.sizeCitiesList();
											for(int j= 0 ; j<size2 ; j++)
											{
												if(cities.getCityDescriptors().elementAt(i).getID() == citiesPref.getCityDescriptors().elementAt(j).getID())
												{
													checked = "checked";
												}
											}
										}
										
							%>
								<input type="checkbox" name="chbx" value="<%= cities.getCityDescriptors().elementAt(i).getID() %>" <%= checked %>> <%= cities.getCityDescriptors().elementAt(i).getName() %>
							<% 			
									}
								}
								if(countries != null)
								{
									int size = countries.sizeCountriesList();
									for(int i=0 ; i<size ; i++)
									{
										String checked = "";
										if(countriesPref != null)
										{
											int size2 = countriesPref.sizeCountriesList();
											for(int j= 0 ; j<size2 ; j++)
											{
												if(countries.getCountryDescriptors().elementAt(i).getID() == countriesPref.getCountryDescriptors().elementAt(j).getID())
												{
													checked = "checked";
												}
											}
										}
							%>
								<input type="checkbox" name="chbx" value="<%= countries.getCountryDescriptors().elementAt(i).getID() %>" <%= checked %>> <%= countries.getCountryDescriptors().elementAt(i).getName() %>
							<% 			
									}
								}
							%>
						</fieldset>
						<fieldset>
							<legend>Save your choice</legend>
							<button type="button" OnClick="document.back.submit();">Back</button><button type="submit">Save</button><button type="reset">Clear</button>
						</fieldset>  
					</form> 
					<form name="back" method="post">
						<input type="hidden" name="action" value="setCompanies">  
					</form> 
				</div>
			</div>
			<jsp:include page="StudentPageFooter.jsp"></jsp:include>
		</div>
	</body>
</html>